<?php
class UsersController extends AppController {

	var $name = 'Users';
	var $uses = null;
	var $helpers = array('Html', 'Form' , 'Javascript');
	var $components = array('Cookie', 'Session');
	
	/*
	function login() {
		if(!empty($this->data)) {
			if($this->data["User"]['email'] == _USERNAME_ && $this->data['User']['password'] == _PASSWORD_) {
				// log user in
				$this->Session->write('user', 1);
				$this->Session->setFlash('You are now logged in.');
		 		$this->redirect(array('controller' => 'newz', 'action' => 'search'));
			} else {
				// bad creditials
				$this->Session->setFlash('That email password combination does not exist.');
			}
		}
	}
	*/
	public function login() {
		$this->layout = 'ajax';
		if(!empty($_REQUEST['username']) && !empty($_REQUEST['password'])) {
		#	$this->log('not empty');
			if($this->params['form']['username'] == _USERNAME_ && $this->params['form']['password'] == _PASSWORD_) {
				$this->log('logged in');
				$this->Session->write('user', 1);
				$this->viewPath = 'newz';
				$this->render('home');
			} else {
				$this->log('not logged in');
				$msg = $_REQUEST['username'] . ' does not equal ' . _USERNAME_;
				$msg .= ' and ' . $_REQUEST['password'] . ' does not equal ' . _PASSWORD_;
				$this->log($msg);
				$this->log(var_export($this->params['form'], true));
			}
		}
	}
}

?>